package com.object_;

public class EqualsExercise01 {
    public static void main(String[] args) {
        Person p1 = new Person("高欢", 20, '男');
        Person p2 = new Person("宇文泰", 20, '男');
        System.out.println(p1.equeals(p2));

    }
}
class Person {
    private String name;
    private int age;
    private char gender;
    public boolean equeals(Object obj) {
        //如果比较的两个对象是同一个对象
        if (this == obj) {
            return true;
        }
        //类型判断
        if (obj instanceof Person) {//类型是Person才比较
            //进行向下转型，取得obj的各个属性
            Person p = (Person)obj;
            return this.name.equals(p.name) && this.age == p.age && this.gender == p.gender;
        }

        //如果不是Person则返回false
        return false;

    }
    public Person(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }
}